package analysis.bean.key;

import analysis.bean.DateDemension;
import analysis.bean.KPIDemension;
import analysis.bean.PlatformDemension;
import analysis.bean.Unit;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Objects;

public class StatsCommon extends StatsUnit {
    public DateDemension dateDemension;
    public PlatformDemension platformDemension;
    public KPIDemension kpiDemension;

    public StatsCommon() {
    }

    public StatsCommon(DateDemension dateDemension, PlatformDemension platformDemension, KPIDemension kpiDemensionUnit) {
        this.dateDemension = dateDemension;
        this.platformDemension = platformDemension;
        this.kpiDemension = kpiDemensionUnit;
    }

    public DateDemension getDateDemension() {
        return dateDemension;
    }

    public void setDateDemension(DateDemension dateDemension) {
        this.dateDemension = dateDemension;
    }

    public PlatformDemension getPlatformDemension() {
        return platformDemension;
    }

    public void setPlatformDemension(PlatformDemension platformDemension) {
        this.platformDemension = platformDemension;
    }

    public KPIDemension getKpiDemension() {
        return kpiDemension;
    }

    public void setKpiDemension(KPIDemension kpiDemension) {
        this.kpiDemension = kpiDemension;
    }

    @Override
    public int compareTo(Unit o) {
        StatsCommon other = (StatsCommon) o;
        if (!this.dateDemension.equals(other.dateDemension)) {
            return this.dateDemension.compareTo(other.dateDemension);
        } else {
            if (!this.platformDemension.equals(other.platformDemension)) {
                return this.platformDemension.compareTo(other.platformDemension);
            } else {
                if (!this.kpiDemension.equals(other.kpiDemension)) {
                    return this.kpiDemension.compareTo(other.kpiDemension);
                }
                return 0;
            }
        }
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        this.dateDemension.write(dataOutput);
        this.platformDemension.write(dataOutput);
        this.kpiDemension.write(dataOutput);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.dateDemension.readFields(dataInput);
        this.platformDemension.readFields(dataInput);
        this.kpiDemension.readFields(dataInput);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        StatsCommon that = (StatsCommon) o;
        return Objects.equals(dateDemension, that.dateDemension) &&
                Objects.equals(platformDemension, that.platformDemension) &&
                Objects.equals(kpiDemension, that.kpiDemension);
    }

    @Override
    public int hashCode() {

        return Objects.hash(dateDemension, platformDemension, kpiDemension);
    }
}
